#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Last Update:

'''打包程序
'''

__revision__ = '0.1'
__author__ = 'lxd'
import sys
sys.path.append('.')
sys.path.append('..')

bin_name = 'bin.py'
#bin_name = 'lxd.py'
icon_name = 'bin.ico'
import os
def getStaticFiles(dir_name):
    r = []
    for root, dirs, files in os.walk(dir_name):
        for file in files:
            r.append(r'%s/%s' %(dir_name, file))
    return r

staticFiles= getStaticFiles('static')
DATA_FILES = ["../MSVCR90.dll", "../gdiplus.dll", "../res.dll", ('static', staticFiles)]

from distutils.core import setup  
import py2exe  
import sys, os


#DATA_FILES = ["../MSVCR90.dll", "../gdiplus.dll", ('static', [r'static/myfont.txt', r'static/songti9.txt', r'static/question.db'])]
#origIsSystemDLL = py2exe.build_exe.isSystemDLL
#def isSystemDLL(pathname):
        #if os.path.basename(pathname).lower() in ("wpcap.dll", "iphlpapi.dll"):
                #return 0
        #return origIsSystemDLL(pathname)
#py2exe.build_exe.isSystemDLL = isSystemDLL

# If run without args, build executables, in quiet mode.
if len(sys.argv) == 1:
    sys.argv.append("py2exe")
    sys.argv.append("-q")

#includes = ["encodings", "encodings.*"]   
INCLUDES = []

MANIFEST_TEMPLATE = """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity
    version="5.0.0.0"
    processorArchitecture="x86"
    name="%(prog)s"
    type="win32"
  />
  <description>%(prog)s</description>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
            level="asInvoker"
            uiAccess="false">
        </requestedExecutionLevel>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
            type="win32"
            name="Microsoft.VC90.CRT"
            version="9.0.21022.8"
            processorArchitecture="x86"
            publicKeyToken="1fc8b3b9a1e18e3b">
      </assemblyIdentity>
    </dependentAssembly>
  </dependency>
  <dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="X86"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
  </dependency>
</assembly>
"""

RT_MANIFEST = 24

options = {"py2exe" :
    {"compressed" : 1,
     "optimize" : 2,
     "bundle_files" : 3,
     "includes" : INCLUDES,
     "excludes" : ["Tkinter",],
     #"dll_excludes": [ "MSVCP90.dll", "mswsock.dll", "powrprof.dll"] }}
     "dll_excludes": [ "MSVCP90.dll", "mswsock.dll", "powrprof.dll", 'wpcap.dll', 'iphlpapi.dll'] }}

windows = [{"script": bin_name,
      "icon_resources": [(1, icon_name)],
      "other_resources" : [(RT_MANIFEST, 1,
                        MANIFEST_TEMPLATE % dict(prog="MyAppName"))],
      }]

setup(name = "MyApp",
      version = "1.0",
      description = "Description of the app",
      author = "lxd",
      author_email ="389009498@qq.com",
      license = "GPL",
      url = "http://projecthomepage.com",

      data_files = DATA_FILES, 
      #zipfile=None,
      options = options,
      windows = windows,
      )

